package com.xudu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xudu.entity.User;
import com.xudu.mapper.UserMapper;
import com.xudu.service.IUserService;
import com.xudu.utils.Resoult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.objenesis.instantiator.perc.PercInstantiator;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName: UserService
 * Description:
 *
 * @Author xudu
 * @Create 2024/4/8
 */

/**
 * 1、实现业务层的接口 alt+enter
 * 2、调用mapper层接口和方法
 */

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {


    @Autowired
    private UserMapper userMapper;

    @Override
    public Resoult login(String username, String password) {

        //User user = userMapper.selectOne(getUsername());
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", username);
        //List<User> users = userMapper.selectList(queryWrapper);
        User user = userMapper.selectOne(queryWrapper);
        if (user==null){
            //代表用户名不存在
            return new Resoult(1000, "用户不存在" , null);
        }else {
            if (user.getPassword().equals(password)){
                return new Resoult(1001, "登陆成功" , user);
            }else {
                //代表密码错误
                return new Resoult(1002, "密码错误" , null);
            }
        }


    }
}
